package com.hemerasolutions.v2trainer.model.exercise.intensity;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;










import com.hemerasolutions.v2trainer.model.base.BaseValueRangeHolder;
import com.hemerasolutions.v2trainer.model.unit.intensity.IntensityUnit;

@Entity
public class Intensity extends BaseValueRangeHolder {

	private static final long serialVersionUID = 1L;

    @ManyToOne
    private IntensityZone intensityZone;
    
	@ManyToOne(fetch = FetchType.LAZY)
	private IntensityUnit intensityUnit;
	
    
	public Intensity() {
		super();
	}

	public Intensity(IntensityUnit iu, IntensityZone iz){
		super();
		this.intensityUnit = iu;
		this.intensityZone = iz;
		this.volumeFactor = iu.getVolumeFactor();
	}	
	
	public Intensity(Intensity other, IntensityZone iz){
		super();
		this.lowValue = other.lowValue;
		this.highValue = other.highValue;
		this.intensityUnit = other.intensityUnit;
		this.intensityZone = iz;
		this.volumeFactor = other.getVolumeFactor();
	}
	
	public IntensityUnit getIntensityUnit() {
		return intensityUnit;
	}

	public void setIntensityUnit(IntensityUnit intensityUnit) {
		this.intensityUnit = intensityUnit;
	}


	public IntensityZone getIntensityZone() {
		return intensityZone;
	}

	public void setIntensityZone(IntensityZone intensityZone) {
		this.intensityZone = intensityZone;
	}
	


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(highValue);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((intensityUnit == null) ? 0 : intensityUnit.hashCode());
		result = prime * result
				+ ((intensityZone == null) ? 0 : intensityZone.hashCode());
		temp = Double.doubleToLongBits(lowValue);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((volumeFactor == null) ? 0 : volumeFactor.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Intensity other = (Intensity) obj;
		if (Double.doubleToLongBits(highValue) != Double
				.doubleToLongBits(other.highValue)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (intensityUnit == null) {
			if (other.intensityUnit != null) {
				return false;
			}
		} else if (!intensityUnit.equals(other.intensityUnit)) {
			return false;
		}
		if (intensityZone == null) {
			if (other.intensityZone != null) {
				return false;
			}
		} else if (!intensityZone.equals(other.intensityZone)) {
			return false;
		}
		if (Double.doubleToLongBits(lowValue) != Double
				.doubleToLongBits(other.lowValue)) {
			return false;
		}
		if (volumeFactor == null) {
			if (other.volumeFactor != null) {
				return false;
			}
		} else if (!volumeFactor.equals(other.volumeFactor)) {
			return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Intensity [id=" + id + ", lowValue=" + lowValue
				+ ", highValue=" + highValue + ", intensityZone="
				+ intensityZone + ", intensityUnit=" + intensityUnit
				+ ", volumeFactor=" + volumeFactor + "]";
	}



	
	
}
